/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufpr.tads.suck.model;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author ni_linda
 */
public class PainelDao {
    private final Connection connection;
    private final String sqlselect = "SELECT agendamento.id, pessoa.nome, agendamento.dataag, agendamento.situacao FROM agendamento, pessoa WHERE estado = 1 AND situacao > 0 AND pessoa.id = agendamento.Pessoa_id ORDER BY agendamento.situacao, agendamento.dataag";

    public PainelDao() throws IOException, FileNotFoundException, ClassNotFoundException, SQLException {
        this.connection = ConnectionFactory.getConnection();
    }
    public List<PainelDto> listPainel() throws SQLException{
         PreparedStatement stmt = connection.prepareStatement(sqlselect);
         ResultSet rs = stmt.executeQuery();
         List<PainelDto> listPainel = new ArrayList();
         while(rs.next()){
            PainelDto agendamento = new PainelDto();
            agendamento.setNumero(rs.getInt("id"));
            agendamento.setNome(rs.getString("nome"));
            agendamento.setSituacao(rs.getInt("situacao"));
            agendamento.setDatahr(rs.getTimestamp("dataag"));
            listPainel.add( agendamento );
        }
       return listPainel;
    }
}
